package cn.zysuyuan.item.controller;

import cn.zysuyuan.common.entity.PageResult;
import cn.zysuyuan.common.entity.R;
import cn.zysuyuan.item.entity.MedicinalProductBase;
import cn.zysuyuan.item.service.MedicinalProductBaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author flypig
 * @version 1.0
 * @date 2019/10/30 2:40
 */

@Api(tags = "药材生产基地关联")
@RestController
@RequestMapping("medicinalProductBase")
public class MedicinalProductBaseController {

    @Autowired
    private MedicinalProductBaseService medicinalProductBaseService;

    @ApiOperation(value = "种植基地列表管理", notes = "种植基地列表管理")
    @GetMapping("productBaseData")
    public ResponseEntity<PageResult<MedicinalProductBase>> queryProductBase(@RequestParam Map<String,Object> map){
        PageResult result = this.medicinalProductBaseService.selectList(map);
//        if (CollectionUtils.isEmpty(result.getRows())) {
//            return ResponseEntity.notFound().build();
//        }
        return ResponseEntity.ok(result);
    }

    @ApiOperation(value = "保存信息", notes ="保存信息")
    @PostMapping("productBaseData")
    public R save(@RequestBody MedicinalProductBase medicinalProductBase) {
        medicinalProductBaseService.insert(medicinalProductBase);
        return R.ok();
    }

    @ApiOperation(value="修改药材产地信息", notes="修改药材产地信息")
    @PutMapping("productBaseData")
    public R update(@RequestBody MedicinalProductBase medicinalProductBase) {
        medicinalProductBaseService.update(medicinalProductBase);
        return R.ok();
    }


    @ApiOperation(value="删除信息", notes="删除信息")
    @DeleteMapping("productBaseData")
    public R delete(@RequestParam("id") String id) {
        medicinalProductBaseService.delete(id);
        return R.ok();
    }




    @ApiOperation(value="药材质量监测中的药材性状图片上传", notes="药材质量监测中的药材性状图片上传")
    @PostMapping("/uploadTMedicinalSharpImg")
    public Map<String, Object> upLoadbMedicinalSharpImg(MultipartFile file, HttpServletRequest
            request, @RequestParam Map<String, Object> map) {
        return medicinalProductBaseService.saveImg(file,request,map);
    }



    @ApiOperation(value="药材质量监测中的药材鉴定图片上传", notes="药材质量监测中的药材鉴定图片上传")
    @PostMapping("/uploadTMedicinalIdentifyImg")
    public Map<String, Object> upLoadbMedicinalIdentifyImg(MultipartFile file,HttpServletRequest
            request,@RequestParam Map<String, Object> map) {
        return medicinalProductBaseService.saveImg(file,request,map);
    }




    @ApiOperation(value="药材质量监测中的特征图谱照片上传", notes="药材质量监测中的特征图谱照片上传")
    @PostMapping("/uploadTMedicinalFeatureImg")
    public Map<String, Object> upLoadbMedicinalFeatureImg(MultipartFile file,HttpServletRequest
            request,@RequestParam Map<String, Object> map) {

        return medicinalProductBaseService.saveImg(file,request,map);
    }


}
